/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-24     RT-Thread    first version
 *  led多文件形式
 *  需要在工程属性->"C/C++常规"->"路径和符号"->"包含"添加led的路径
 *
 *  2个线程闪烁LED
 */
//#include "stm32f1xx_hal_gpio.h"
#include <rtthread.h>
#include "led.h"
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

struct rt_thread rt_led1_thread;
struct rt_thread rt_led2_thread;
void led1_thread_entry(void *p_arg);
void led2_thread_entry(void *p_arg);
ALIGN(RT_ALIGN_SIZE)
rt_uint8_t rt_led1_thread_stack[512];
rt_uint8_t rt_led2_thread_stack[512];
int main(void)
{
    MX_GPIO_Init();

  LOG_D("HelloSSS RT-Thread!");
  rt_thread_init(&rt_led1_thread, "led1", led1_thread_entry, RT_NULL, &rt_led1_thread_stack[0], sizeof(rt_led1_thread_stack), 2, 4);
  rt_thread_startup(&rt_led1_thread);
  rt_thread_init(&rt_led2_thread, "led2", led2_thread_entry, RT_NULL, &rt_led2_thread_stack[0], sizeof(rt_led2_thread_stack), 3, 4);
  rt_thread_startup(&rt_led2_thread);

//  rt_system_scheduler_start();

//    while (1)
//    {
//        LOG_D("Idel Thread!");
//        rt_thread_mdelay(1000);
////        rt_thread_delay(2000);
//    }

    return RT_EOK;
}

void led1_thread_entry(void *p_arg)
{
  for(;;)
  {
    LOG_D("led1 on !");
    HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_SET);
    rt_thread_mdelay(1000);
//    rt_thread_delay(900);
    LOG_D("led1 off !");
    HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_RESET);
    rt_thread_mdelay(1000);
//    rt_thread_delay(900);
  }
}
void led2_thread_entry(void *p_arg)
{
    for(;;)
    {
    LOG_D("LED2 ON!");
    HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,GPIO_PIN_RESET);
    rt_thread_mdelay(500);
//    rt_thread_delay(500);
    LOG_D("LED2 OFF!");
    HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,GPIO_PIN_SET);
    rt_thread_mdelay(500);
//    rt_thread_delay(500);
    }
}
